package Lee_code;

import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

/**
 * @author blh
 * @date 2024年06月27日 15:50
 */
public class Lee_82_627 {
    public ListNode deleteDuplicates(ListNode head) {
        Deque<ListNode> deque = new LinkedList<>();
        ListNode dummyHead = new ListNode(-1);
        dummyHead.next = head;
        ListNode slow = head;
        ListNode fast = slow.next;
        // 用于指示是否重复
        boolean duplicate = false;
        deque.push(dummyHead);

        while (slow != null) {
            // 如果重复
            if (deque.peek().val == slow.val) {
                // 推出重复元素
                ListNode temp = deque.pop();

                slow = slow.next;
                while (slow.val == temp.val && slow != null) {
                    slow = slow.next;
                }
            }
            if (slow != null) {
                deque.peek().next = slow;
                deque.push(slow);
            }
        }
        return dummyHead.next;
    }
}
